""" рабочий вариант drag text"""
import sys
import logging                                                                  # запись логов

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *


class Label(QLabel):

    def __init__(self, parent=None):
        super().__init__()
        
    def mousePressEvent(self, pe):
    
        if pe.button() == Qt.LeftButton:
            self.m_ptDragPos = pe.pos()
        QWidget.mousePressEvent(self, pe)
            
    def mouseMoveEvent(self, pe):
        if (pe.buttons() == Qt.LeftButton):
            distance = (pe.pos() - self.m_ptDragPos).manhattanLength()
            if (distance > QApplication.startDragDistance()):
                self.startDrag()
        QWidget.mousePressEvent(self, pe)
        # file=QTemporaryFile()
        # if (file.open()):
            # url = Qurl.fromLocalFile(file.fileName())
            # file.write(text().toUtf8())
            # file.close()

    def startDrag(self):        
        url = QUrl.fromLocalFile("c:\\tmp\\1.txt");
        print(url)
        # url = list(url)
        mimeData = QMimeData()
        mimeData.setUrls([url])  # setUrls ( [QtCore.QUrl ( "http: //google. ru/")])
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(QPixmap('add.png')) 
        drag.exec_(Qt.CopyAction)

        # drag = QDrag(self)
        # mimeData = QMimeData()
        # mimeData.setText("c:\tmp\1.txt")
        # # mimeData.setUrls("c:\tmp\1.txt")
        # drag.setMimeData(mimeData)
        # drag.setPixmap(QPixmap('add.png')) 
        # drag.exec_(Qt.CopyAction)
            
if __name__ == '__main__':                                                      

    app = QApplication(sys.argv)
    label = Label()
    label.setText("foo bar");
    label.show();
    sys.exit(app.exec_())                                                       # Запускаем цикл обработки событий
